// columns转换
export function columnsToTableColumns(columns) {
  return columns.filter(function (r) {
    return r.isDisplay;
  }).map(function (r) {
    return {
      sortable: false,
      dataIndex: r.fieldName,
      title: r.fieldAlias || r.fieldName,
      flex: 1,
      format: r.format,
      width: r.fieldWidth || 100
    };
  });
}

// queryItems转换
export function queryItemsToFormItems(queryItems) {
  return queryItems.map(function (r) {
    var item = {
      label: r.fieldAlias || r.fieldName,
      name: r.fieldName
    };
    r.helpId && (item.helpId = r.helpId);
    r.displayType && (item.xtype = r.displayType);
    r.enumValue && (item.data = r.enumValue.split(';').map(function (item) {
      var vl = item.split('|');
      return {
        value: vl[0],
        label: vl[1]
      };
    }));
    return item;
  });
}
/**
 * 根据filters过滤符合条件的index集合
 * @param arr
 * @param filters
 * @returns
 */
export function findFilterIndexes(arr, func) {
  var result = [];
  arr.forEach(function (it, index) {
    if (func(it)) {
      result.push(index);
    }
  });
  return result;
}

/**
 * 递归找到当前节点&子节点keys
 *  @param treeList
 *  @returns string[]
 */
export function loopTreeChildren(treeList) {
  var result = [];
  treeList.forEach(function (it) {
    var _it$children;
    result.push(it.key);
    if ((_it$children = it.children) !== null && _it$children !== void 0 && _it$children.length) {
      result = result.concat(loopTreeChildren(it.children));
    }
  });
  return result;
}